package com.notime.web.converter;

import java.util.Locale;

import org.joda.time.LocalTime;

import com.vaadin.data.util.converter.Converter;

/**
 * Converts times from java.lang.String to org.joda.time.LocalTime representation
 */
public class StringToLocalTimeConverter implements Converter<String, LocalTime> {

  /**
	 * 
	 */
	private static final long serialVersionUID = -5393561382301382813L;

@Override
  public LocalTime convertToModel(String value, Class<? extends LocalTime> targetType, Locale locale)
      throws com.vaadin.data.util.converter.Converter.ConversionException {
    return LocalTime.parse(value);
  }

  @Override
  public String convertToPresentation(LocalTime value, Class<? extends String> targetType, Locale locale)
      throws com.vaadin.data.util.converter.Converter.ConversionException {
    return value.toString("HH:mm");
  }

  @Override
  public Class<LocalTime> getModelType() {
    return LocalTime.class;
  }

  @Override
  public Class<String> getPresentationType() {
    return String.class;
  }

}
